package com.web.action;

import com.util.BaseAction;
import com.util.JsonUtil;
import com.web.domain.City;
import com.web.domain.Hotel;
import com.web.domain.Room;
import com.web.service.CityService;
import com.web.service.HotelService;
import com.web.vo.Page;
import com.web.vo.RoomVo;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.List;

/**
 * Created by 陈国钰 on 2016/9/5.
 */
@Controller
@Scope("prototype")
@ParentPackage(value = "struts-default")
@Namespace(value = "/")
@Action(value = "hotelAction", results = {
        @Result(name = "search", location = "/search/search.jsp"),
        @Result(name = "room", location = "/search/room.jsp")
})
public class HotelAction extends BaseAction {
    private List<City> cityList;
    private List<Hotel> hotelList;
    private String cityName;
    private int hotelId;
    private List<Room> roomList;
    private Page page;
    private String landmarks;
    private List<RoomVo> roomVos;
    @Autowired
    private HotelService hotelService;
    @Autowired
    private CityService cityService;


    public String searchCity() {
        cityList = cityService.searchCity();
        return "search";
    }

    public String searchLandmarks(){
        List<String> landmarks = cityService.searchLandmarks(cityName);
        JsonUtil.jsonOut(landmarks);
        return NONE;
    }

    public String searchAreaName(){
        cityList = cityService.searchAreaName(cityName,landmarks);
        return NONE;
    }

    public String searchHotel() throws IOException {
        hotelList = hotelService.searchHotel(cityName);
        JsonUtil.jsonOut(hotelList);
        return NONE;
    }


    public String searchRoom() throws IOException {
        roomVos = hotelService.searchRoom(hotelId);
        JsonUtil.jsonOut(roomVos);
        return NONE;
    }



    public List<Hotel> getHotelList() {
        return hotelList;
    }

    public void setHotelList(List<Hotel> hotelList) {
        this.hotelList = hotelList;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public List<City> getCityList() {
        return cityList;
    }

    public void setCityList(List<City> cityList) {
        this.cityList = cityList;
    }

    public int getHotelId() {
        return hotelId;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public void setHotelId(int hotelId) {
        this.hotelId = hotelId;
    }

    public List<Room> getRoomList() {
        return roomList;
    }

    public void setRoomList(List<Room> roomList) {
        this.roomList = roomList;
    }

    public String getLandmarks() {
        return landmarks;
    }

    public void setLandmarks(String landmarks) {
        this.landmarks = landmarks;
    }

    public List<RoomVo> getRoomVos() {
        return roomVos;
    }

    public void setRoomVos(List<RoomVo> roomVos) {
        this.roomVos = roomVos;
    }

    public String execute() throws Exception {
        return null;
    }
}
